/**
 * Created by zhanglihe on 15/11/7.
 */
require.config(require_config);

define([
    'jquery',
    'common',
    'ready',
    'collection',
    'template',
    'model',
    'dialog',
    'datepicker'
], function ($, common, ready, Collection, template, Model, dialog, datepicker) {
    var index = function () {
        this.init();
    };
    index.prototype = {
        init: function () {
            loading();
            this.fetch();
            this.event();
        },

        fetch: function () {
            var _this = this;
            this.collection = new Collection({
                condition: {limit: 100, offset: 0},
                url: _global.url.api + 'goods_sale',
                callback: function () {
                    loaded();
                }
            });
            this.collection.fetch();
        },

        event: function () {
            this.data = {};
            var _this = this;
            //保存
            $('.long_date').on('click', function () {
                WdatePicker({
                    el: this.id,
                    dateFmt: 'yyyy-MM-dd HH:mm:ss'
                });
            });//1111
            $('#btn-search').on('click', function (e) {
                e.preventDefault();
                _this.collection.condition.keyword = $("input[name='keyword']").val();
                _this.collection.condition.start_time = $("#start_time").val();
                _this.collection.condition.end_time = $("#end_time").val();
                _this.collection.reload();
            });
            $('#btn-status').find('a').on('click', function (e) {
                e.preventDefault();
                _this.collection.condition.status = $(e.target).attr('rel');
                _this.collection.reload();
                $(e.target).addClass('active').siblings().removeClass('active');
                $(".field").html("");
                if ($(e.target).prop("rel") == 2) {
                    $(".field-2").html("↓");
                }
                else {
                    $(".field-1").html("↓");
                }
            });
        }
    };

    new index();

});